package com.cloudkinto.service.platform.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cloudkinto.annotate.GraphqlResultAttributesBuilder;
import com.cloudkinto.bo.order.makeshop.MakeShopShopConfig;
import com.cloudkinto.bo.order.makeshop.getProduct.SearchProductRequest;
import com.cloudkinto.bo.order.makeshop.getProduct.SearchProductResponse;
import com.cloudkinto.common.RabbitQueueConstant;
import com.cloudkinto.common.RedisKeyConstants;
import com.cloudkinto.common.common.DateUtils;
import com.cloudkinto.common.constant.SysConstant;
import com.cloudkinto.common.exception.BizException;
import com.cloudkinto.common.utils.*;
import com.cloudkinto.common.utils.dict.StaticDict;
import com.cloudkinto.common.web.PageResult;
import com.cloudkinto.common.web.SingleResult;
import com.cloudkinto.dao.PlatformStoreDao;
import com.cloudkinto.entity.PlatformStoreDo;
import com.cloudkinto.service.consumer.vo.rakuten.ItemUpdateConsumerReq;
import com.cloudkinto.service.platform.PlatformStoreService;
import com.cloudkinto.service.platform.vo.store.*;
import com.cloudkinto.service.platform.vo.wowma.OrderWowmaEntity;
import com.cloudkinto.utils.MakeShopGraphqlUtils;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.jdom2.JDOMException;
import org.json.XML;
import org.mountcloud.graphql.request.param.RequestObjectParameter;
import org.mountcloud.graphql.request.result.ResultAttributtes;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
 * <p>
 * service实现类
 * </p>
 *
 * @author hua
 * @since 2024-12-25
 */
@Service
@RequiredArgsConstructor
@Transactional(rollbackFor = Exception.class)//事务回滚
public class PlatformStoreServiceImpl extends ServiceImpl<PlatformStoreDao, PlatformStoreDo> implements PlatformStoreService {
    private final PlatformStoreDao dao;
    private final RedisTemplate redisTemplate;
    private final RabbitTemplate rabbitTemplate;

    /**
     * 店铺代码不能重复
     */
    @Override
    public boolean check(Long id, String storeCode, Long companyId) {
        Integer count = dao.selectCount(new LambdaQueryWrapper<PlatformStoreDo>()
                .eq(PlatformStoreDo::getStoreCode, storeCode).ne(id != null, PlatformStoreDo::getId, id).eq(PlatformStoreDo::getCompanyId, companyId));
        return count <= 0;
    }

    @Override
    public Object update(PlatformUpdateReq req, Long userId, Long companyId) {
        PlatformStoreDo entityDo = dao.selectById(req.getId());
        if (entityDo == null || !Objects.equals(entityDo.getCompanyId(), companyId)) {
            return null;
        }
        entityDo.setAuthExpireTime(req.getAuthExpireTime());
        entityDo.setStoreName(req.getStoreName());
        dao.updateById(entityDo);
        return entityDo.getId();
    }

    /**
     * 停用启用
     */
    @Override
    public Object ableStatus(PlatformUpdateStatusReq req, Long userId, Long companyId) {
        PlatformStoreDo entityDo = dao.selectById(req.getId());
        if (entityDo == null || !Objects.equals(entityDo.getCompanyId(), companyId)) {
            return null;
        }
        if (req.getStoreStatus() != null) {
            entityDo.setStoreStatus(req.getStoreStatus());
            dao.updateById(entityDo);
        } else if (req.getAuthSyncStatus() != null) {
            if (req.getAuthSyncStatus() == 1) {
                //授权成功 可以暂停同步
                if (entityDo.getAuthSyncStatus() != 2) {
                    return null;
                }
                entityDo.setAuthSyncStatus(1);
            } else if (req.getAuthSyncStatus() == 2) {//暂停同步
                if (entityDo.getAuthSyncStatus() != 1) {
                    return null;
                }
                entityDo.setAuthSyncStatus(2);
            } else {
                return null;
            }
            dao.updateById(entityDo);
        }
        return null;
    }

    @Override
    public int delete(Long id, Long userId) {
        PlatformStoreDo entityDo = dao.selectById(id);
        handlerDeleteBefore(entityDo, userId);
        dao.updateById(entityDo);
        return dao.deleteById(id);
    }

    //做删除之前要执行的业务定制处理
    private void handlerDeleteBefore(PlatformStoreDo entityDo, Long userId) {
        entityDo.setDeleteBy(userId);
        entityDo.setDeleteTime(new Date());
    }


    @Override
    public SingleResult pageInit() {
        Map<String, Object> result = new HashMap<>();
        List<Map<Object, Object>> orderReturnStatus = StaticDict.getPlatformOrder_Amazon_Market();
        result.put("amazonMarketList", orderReturnStatus);
        result.put("platformCode", StaticDict.getStore_PlatformCode());
        result.put("authSyncStatusList", StaticDict.getPlatform_Store_AuthSyncStatus());
        return SingleResult.success(result);
    }

    @Override
    public List<PlatformStoreRes> getList(Long companyId, Long tenantId, String source) {
        Map<String, String> map = new HashMap<>();
        if (companyId == null) {
            return new ArrayList<>();
        }
        map.put("source", source);
        map.put("tenantId", tenantId + "");
        map.put("companyId", companyId + "");
        return this.getList(map);
    }

    @Override
    public List<PlatformStoreRes> getList(Long companyId) {
      return this.getList(companyId, null, StaticDict.System_Source.OMS.getValue());
    }

    @Override
    public List<PlatformStoreRes> getList(Map<String, String> map) {
        QueryWrapper<PlatformStoreDo> wrapper = queryBuild(map);
        List<PlatformStoreDo> list = this.list(wrapper);
        List<PlatformStoreRes> result = handlerListAfter(list);
        return result;
    }

    @Override
    public PageResult getListPage(Map<String, String> map) {
        QueryWrapper<PlatformStoreDo> wrapper = queryBuild(map);
        IPage<PlatformStoreDo> page = pageInit(map);
        page = this.page(page, wrapper);
        List<PlatformStoreRes> resList = handlerListAfter(page.getRecords());
        PageResult result = new PageResult(resList, (int) page.getCurrent(), (int) page.getSize(), (int) page.getTotal(), (int) page.getPages());
        return result;
    }


    @Override
    public List<Map<String, Object>> statusStatistics(Map<String, String> map) {
        map.remove("storeStatus");
        QueryWrapper<PlatformStoreDo> wrapper = queryBuild(map);
        Map<String, List<PlatformStoreDo>> platformCodeMap = this.list(wrapper).stream().collect(Collectors.groupingBy(PlatformStoreDo::getPlatformCode));

        List<Map<String, Object>> resultList = new ArrayList<>();
        for (StaticDict.Store_PlatformCode value : StaticDict.Store_PlatformCode.values()) {
            Map<String, Object> m = new HashMap<>();
            m.put("id", value.getValue());
            m.put("name", value.getText());
            int storeCount = platformCodeMap.get(value.getValue()) == null ? 0 : platformCodeMap.get(value.getValue()).size();
            m.put("sum", storeCount);
            if (storeCount == 0) {
                m.put("enableSum", 0);
            } else {
                m.put("enableSum", (int) platformCodeMap.get(value.getValue()).stream().filter(i -> i.getStoreStatus() == 1 && i.getAuthSyncStatus() == 1).count());
            }
            resultList.add(m);
        }
        return resultList;
    }


    //查询分页列表之后对列表数据的处理
    private List<PlatformStoreRes> handlerListAfter(List<PlatformStoreDo> list) {
        List<PlatformStoreRes> result = new ArrayList<>();
        list.forEach(et -> {
            result.add(new PlatformStoreRes(et.getId(), et.getStoreName(), et.getStoreCode(), et.getStoreStatus(), et.getPlatformCode(),
                    et.getAuthSyncStatus(), et.getAuthSyncTime(), et.getAuthExpireTime(), et.getSite(), et.getRegionCode(), et.getCompanyId(), et.getSellerId(), et.getSignatureVersion(), et.getAppSecret(), et.getPresale()));
        });
        return result;
    }

    private IPage<PlatformStoreDo> pageInit(Map<String, String> map) {
        IPage<PlatformStoreDo> page = new Page();
        page.setSize(StringUtils.isNotBlank(map.get("pageSize")) ? Long.parseLong(map.get("pageSize")) : 10);
        page.setCurrent(StringUtils.isNotBlank(map.get("current")) ? Long.parseLong(map.get("current")) : 1);
        return page;
    }

    private QueryWrapper<PlatformStoreDo> queryBuild(Map<String, String> map) {
        QueryWrapper<PlatformStoreDo> wrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(map.get("keyword"))) {
            wrapper.like("store_name", map.get("keyword"));
        }
        if (StringUtils.isNotBlank(map.get("platformCode"))) {
            wrapper.eq("platform_code", map.get("platformCode"));
        }
        if (StringUtils.isNotBlank(map.get("storeStatus"))) {
            wrapper.eq("store_status", map.get("storeStatus"));
        }
        if (StringUtils.isNotBlank(map.get("authSyncStatus"))) {
            wrapper.eq("auth_sync_status", map.get("authSyncStatus"));
        }
        if (StringUtils.isNotBlank(map.get("site"))) {
            wrapper.eq("site", map.get("site"));
        }
        String source = map.getOrDefault("source", StaticDict.System_Source.OMS.getValue());
        if (StaticDict.System_Source.OMS.getValue().equals(source)) {
            wrapper.eq("company_id", map.get("companyId"));
        }
        else {
            wrapper.eq("tenant_id", map.get("tenantId"));
        }
        wrapper.orderByDesc("id");
        return wrapper;
    }


    @Override
    public void updateStoreAuthStatus(Long storeId) {
        LambdaUpdateWrapper<PlatformStoreDo> updateWrapper = new LambdaUpdateWrapper<>();
//        updateWrapper.set(PlatformStoreDo::getServiceToken, null);
        updateWrapper.set(PlatformStoreDo::getAuthSyncStatus, 4);
        updateWrapper.eq(PlatformStoreDo::getId, storeId);
        this.update(updateWrapper);
        log.debug("店铺:" + (storeId) + "授权令牌过期，请重新授权");
    }

    @Override
    public void updateStorePresale(Long storeId, Integer presales, Long userId) {
        if (presales == null || (presales != 0 && presales != 1)) {
            return;
        }
        LambdaUpdateWrapper<PlatformStoreDo> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(PlatformStoreDo::getPresale, presales);
        updateWrapper.set(PlatformStoreDo::getUpdateTime, new Date());
        updateWrapper.set(PlatformStoreDo::getUpdateBy, userId);
        updateWrapper.eq(PlatformStoreDo::getId, storeId);
        this.update(updateWrapper);
    }


    @Override
    public PlatformStoreDo amazonStoreAdd(StoreAmazonAddReq req, Long userId) {
        PlatformStoreDo storeDo = new PlatformStoreDo();
        storeDo.setPlatformCode("amazon");
        storeDo.setStoreCode(req.getStoreCode());
        storeDo.setStoreName(req.getStoreName());
        storeDo.setRegionCode(req.getRegionCode());
        storeDo.setAuthSyncStatus(0);
        storeDo.setStoreStatus(1);
        dao.insert(storeDo);
        return storeDo;
    }


    @Override
    public PlatformStoreDo yahooStoreAdd(StoreYahooAddReq req, Long userId) {
        PlatformStoreDo storeDo = new PlatformStoreDo();
        storeDo.setPlatformCode("yahoo");
        storeDo.setStoreCode(req.getStoreCode());
        storeDo.setStoreName(req.getStoreName());
        storeDo.setAuthSyncStatus(0);
        storeDo.setStoreStatus(1);
        storeDo.setSellerId(req.getSellerId());
//        storeDo.setAppKey(req.getAppKey());
        storeDo.setAppSecret(req.getAppSecret());
        storeDo.setSignatureVersion(req.getSignatureVersion());
//        storeDo.setAuthExpireTime(DateUtils.passingDate(new Date(), 28));
//        storeDo.setServiceToken(req.getServiceToken());
        dao.insert(storeDo);
        return storeDo;
    }

    @Override
    public void rakutenStoreAdd(StoreRakutenAddReq req, Long userId, Long companyId) {
        boolean check = this.check(req.getId(), req.getStoreCode(), companyId);
        if (!check) {
            throw new BizException("店铺代码已存在");
        }
        //https://api.rms.rakuten.co.jp/es/1.0/shop/shopMaster
//        Map<String, Object> map = new JSONObject();
//        map.put("startDatetime", DateUtils.dateFormatToString(DateUtils.passingDate(new Date(), -1), "yyyy-MM-dd'T'HH:mm:ss+0900"));
//        map.put("endDatetime", DateUtils.dateFormatToString(new Date(), "yyyy-MM-dd'T'HH:mm:ss+0900"));
//        map.put("dateType", 1);//1,订单创建时间 3订单支付时间
//        map.put("orderProgressList", new int[]{100, 200, 300, 400, 500, 600, 700, 800, 900});
//        Map<String, Object> page = new HashMap<>();
//        page.put("requestRecordsAmount", 100);
//        page.put("requestPage", 1);
//        map.put("PaginationRequestModel", page);
//        String url = GlobalConstants.RakutenURL + "/order/searchOrder/";
//        String jsonData = RakutenUtil.raAPidoPOST(url, req.getAppSecret(), req.getAppKey(), map);
//        if (StringUtils.isBlank(jsonData)) {
//            throw new BizException("连接超时,请重试");
//        }
//        JSONObject object = JSONObject.parseObject(jsonData);
//        JSONArray messageModelList = object.getJSONArray("MessageModelList");
//        //{ "Results": { "errorCode": "ES01-01", "message": "Un-Authorised"}}
//        if (messageModelList == null) {
//            JSONObject jsonObject1 = object.getJSONObject("Results");
//            if (jsonObject1 != null) {
//                if (jsonObject1.getString("errorCode") != null && "ES01-01".equals(jsonObject1.getString("errorCode"))) {
//                    //授权过期，把店铺授权状态改为过期状态 todo
//                    throw new BizException("密钥不正确");
//                }
//            }
//            throw new BizException("授权失败, 请检查密钥");
//        }
//        if ("ERROR".equals(messageModelList.getJSONObject(0).getString("messageType"))) {
//            //错误的情况
//            String message = messageModelList.getJSONObject(0).getString("message");
//            throw new BizException(message);
//        }

        //https://api.rms.rakuten.co.jp/es/1.0/shop/shopMaster
        Map<String, Object> map = new JSONObject();

        String url = "https://api.rms.rakuten.co.jp/es/1.0/shop/shopMaster";
        String jsonData = null;
        try {
            jsonData = RakutenUtil.raAPidoGet(url, req.getAppSecret(), req.getAppKey(), "application/xml; charset=UTF-8", map);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        if (StringUtils.isBlank(jsonData)) {
            throw new BizException("连接超时,请重试");
        }
        String shopUrl = null;
        org.json.JSONObject object = XML.toJSONObject(jsonData);
        if (object.has("errors")) {
            if (object.getJSONObject("errors").has("element")
                    && object.getJSONObject("errors").getJSONObject("element").has("code")
                    && object.getJSONObject("errors").getJSONObject("element").has("message")) {
                throw new BizException(object.getJSONObject("errors").getJSONObject("element").getString("code") + ":"
                        + object.getJSONObject("errors").getJSONObject("element").getString("message") + "; 请确认密钥是否正确 且 shopMaster API在利用中");
            } else {
                throw new BizException("Rakuten店铺授权失败, 请确认密钥是否正确 且 shopMaster API在利用中");
            }
        } else if (object.has("shopbiz:shopBizApiResponse")) {
            org.json.JSONObject shopBizApiResponse = object.getJSONObject("shopbiz:shopBizApiResponse");
            if (shopBizApiResponse.has("result") && shopBizApiResponse.getJSONObject("result").has("shopMaster")
                    && shopBizApiResponse.getJSONObject("result").getJSONObject("shopMaster").has("url")) {
                shopUrl = shopBizApiResponse.getJSONObject("result").getJSONObject("shopMaster").getString("url");

            }

        } else {
            throw new BizException("Rakuten店铺授权失败, 请确认密钥是否正确 且 shopMaster API在利用中");
        }
        PlatformStoreDo storeDo = new PlatformStoreDo();
        storeDo.setPlatformCode("rakuten");
        storeDo.setStoreCode(req.getStoreCode());
        storeDo.setStoreName(req.getStoreName());
        storeDo.setAuthSyncStatus(1);
        storeDo.setStoreStatus(1);
        storeDo.setAuthSyncTime(new Date());
        storeDo.setAppKey(req.getAppKey());
        storeDo.setAppSecret(req.getAppSecret());
        storeDo.setId(req.getId());
        storeDo.setAuthExpireTime(req.getAuthExpireTime());
        storeDo.setShopUrl(shopUrl);
        this.saveOrUpdate(storeDo);
    }

    @Override
    public PlatformStoreDo shopifyStoreAdd(StoreShopifyAddReq req, Long userId) {
        PlatformStoreDo storeDo = new PlatformStoreDo();
        storeDo.setPlatformCode("shopify");
        storeDo.setStoreCode(req.getStoreCode());
        storeDo.setStoreName(req.getStoreName());
        storeDo.setAuthSyncStatus(0);
        storeDo.setStoreStatus(1);
        storeDo.setAppKey(req.getAppKey());
        dao.insert(storeDo);
        return storeDo;
    }

    @Override
    public PlatformStoreDo maekshopStoreAdd(StoreMakeshopAddReq req, Long userId, Long companyId) {
        boolean check = this.check(req.getId(), req.getStoreCode(), companyId);
        if (!check) {
            throw new BizException("店铺代码已存在");
        }
        //验证密钥是否正确
        SearchProductRequest searchProductRequest = new SearchProductRequest();
        searchProductRequest.setLastUpdateFrom("2023-04-25 00:00:00");
        searchProductRequest.setLastUpdateTo("2025-04-27 00:00:00");
        searchProductRequest.setPage(1);
        searchProductRequest.setLimit(1);
        ResultAttributtes[] resultAttributtes = GraphqlResultAttributesBuilder.build(SearchProductResponse.class);
        Map<String, Object> request = new HashMap<>(2);
        request.put("input", new RequestObjectParameter(searchProductRequest));
        try {
            MakeShopGraphqlUtils.postGraphqlQuery(
                    MakeShopShopConfig.builder().url(req.getUrl()).apiKey(req.getApiKey()).token(req.getToken()).build(),
                    "searchProduct",
                    request,
                    SearchProductResponse.class,
                    resultAttributtes
            );
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            throw new BizException("密钥不正确");
        }
        PlatformStoreDo storeDo = new PlatformStoreDo();
        storeDo.setPlatformCode("makeshop");
        storeDo.setStoreCode(req.getStoreCode());
        storeDo.setStoreName(req.getStoreName());
        storeDo.setAppKey(req.getApiKey());
        storeDo.setServiceToken(req.getToken());
        storeDo.setShopUrl(req.getUrl());
        storeDo.setAuthSyncStatus(1);
        storeDo.setStoreStatus(1);
        dao.insert(storeDo);
        return storeDo;

    }


    @Override
    public void qoo10StoreAdd(StoreQoo10AddReq req, Long userId, Long companyId) {
        boolean check = this.check(req.getId(), req.getStoreCode(), companyId);
        if (!check) {
            throw new BizException("店铺代码已存在");
        }
        //验证密钥是否正确
        String qoo10Token = Qoo10Utils.getQoo10Token(req.getSellerId(), req.getAppKey(), req.getAppSecret());
        if (StringUtils.isBlank(qoo10Token)) {
            throw new BizException("密钥不正确");
        }
        PlatformStoreDo storeDo = new PlatformStoreDo();
        storeDo.setPlatformCode("qoo10");
        storeDo.setStoreCode(req.getStoreCode());
        storeDo.setStoreName(req.getStoreName());
        storeDo.setAuthSyncStatus(1);
        storeDo.setStoreStatus(1);
        storeDo.setAuthSyncTime(new Date());
        storeDo.setAppKey(req.getAppKey());
        storeDo.setAppSecret(req.getAppSecret());
        storeDo.setId(req.getId());
        storeDo.setAuthExpireTime(req.getAuthExpireTime());
        storeDo.setSellerId(req.getSellerId());
        this.saveOrUpdate(storeDo);
        //同步商品
        PlatformStoreDo platformStoreDo = dao.selectById(storeDo.getId());
        if (platformStoreDo != null) {
            rabbitTemplate.convertAndSend(RabbitQueueConstant.GetPlatformProduct_Qoo10, JSON.toJSONString(new ItemUpdateConsumerReq(platformStoreDo, null, null)));
        }
    }

    @Override
    public void wowmaStoreAdd(StoreWowmaAddReq req, Long userId, Long companyId) {
        boolean check = this.check(req.getId(), req.getStoreCode(), companyId);
        if (!check) {
            throw new BizException("店铺代码已存在");
        }
        String url = "https://api.manager.wowma.jp/wmshopapi/searchTradeInfoListProc";
        Map<String, Object> bodyMap = new HashMap<>();
        bodyMap.put("startDate", DateUtils.dateFormatToString(new Date(), "yyyy-MM-dd"));
        bodyMap.put("endDate", DateUtils.dateFormatToString(new Date(), "yyyy-MM-dd"));
        bodyMap.put("shopId", req.getSellerId());
        bodyMap.put("dateType", 2);//入金日
        bodyMap.put("totalCount", 1);
        bodyMap.put("startCount", 1);
        String jsonData = null;
        try {
            jsonData = WowmaUtil.raAPidoGet(url, req.getAppSecret(), bodyMap);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (StringUtils.isBlank(jsonData)) {
            throw new BizException("连接超时, 请重试");
        }
        JSONObject object = null;
        List<OrderWowmaEntity> list = null;
        try {
            object = XmlUtils.xml2Json(jsonData);
        } catch (JDOMException | IOException e) {
            e.printStackTrace();
        }
        if (object == null || object.get("response") == null || object.getJSONObject("response").getString("result") == null) {
            throw new BizException("连接超时, 请重试");
        }
        JSONObject result = object.getJSONObject("response").getJSONArray("result").getJSONObject(0);
        if (StringUtils.isBlank(result.getString("status"))) {
            throw new BizException("连接超时, 请重试");
        } else if ("1".equals(result.getString("status"))) {
            JSONObject error = result.getJSONArray("error").getJSONObject(0);
            if ("0002".equals(error.getString("code"))) {
                //message -> 認証に失敗しました。 授权过期了
                throw new BizException("密钥不正确");

            }
            throw new BizException(error.getString("message"));
        }
        PlatformStoreDo storeDo = new PlatformStoreDo();
        storeDo.setPlatformCode(StaticDict.Store_PlatformCode.Wowma.getValue());
        storeDo.setStoreCode(req.getStoreCode());
        storeDo.setStoreName(req.getStoreName());
        storeDo.setSellerId(req.getSellerId());
        storeDo.setAuthSyncStatus(1);
        storeDo.setStoreStatus(1);
        storeDo.setAuthSyncTime(new Date());
        storeDo.setAppSecret(req.getAppSecret());
        storeDo.setId(req.getId());
        storeDo.setAuthExpireTime(req.getAuthExpireTime());
        this.saveOrUpdate(storeDo);
    }


    @Override
    public List<String> getAboutToExpireStoreList(Long userId, Long companyId) {
        String key = RedisKeyConstants.PlatformStore_Auth_Remind_ + DateUtils.dateFormatToString(new Date());
        //判断此用户是不是 提醒过
        Boolean member = redisTemplate.opsForSet().isMember(key, userId);
        if (member != null && member) {//改成一直提醒
//            return null;
        }
        List<PlatformStoreDo> storeDoList = dao.getAboutToExpireStoreList(companyId);
        List<String> message = new ArrayList<>();
        for (PlatformStoreDo storeDo : storeDoList) {
            if (storeDo.getAuthSyncStatus() == 4) {
                //过期了
                message.add(StringsUtil.createI18Message(SysConstant.PlatformStore_HadExpire, storeDo.getPlatformCode(), storeDo.getStoreName()));
            } else {
                message.add(StringsUtil.createI18Message(SysConstant.PlatformStore_AuthExpire, storeDo.getPlatformCode(), storeDo.getStoreName()));
            }
        }
        redisTemplate.opsForSet().add(key, userId);
        redisTemplate.expire(key, 60 * 60 * 24, TimeUnit.SECONDS);
        return message;
    }

}
